package com.itoffer.web.old;

import com.itoffer.pojo.Applicant;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

//@WebServlet("/changePasswordServlet")
public class ChangePasswordServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String oldPassword = req.getParameter("oldPassword");
        System.out.println(oldPassword);
        HttpSession session = req.getSession();
        Applicant applicant = (Applicant) session.getAttribute("applicant");
        if(!oldPassword.equals(applicant.getApplicant_pwd())){
            resp.setContentType("text/json;charset=utf8");
            resp.getWriter().write("pwdfalse");
//            req.setAttribute("errormsg","原密码错误，请重新输入");
//            req.getRequestDispatcher("/applicant/changepassword.jsp").forward(req,resp);
            System.out.println("密码错误");
        }else{
            //调用业务层修改密码方法
            System.out.println("密码正确");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
